package miracle.joker.design.command.demo2;

public class AddTextCommand implements Command {
    private Document document;
    private String text;

    public AddTextCommand(Document document, String text) {
        this.document = document;
        this.text = text;
    }

    @Override
    public void execute() {
        document.appendText(text);
    }

    @Override
    public void undo() {
        document.moveCursor(-text.length());
        document.deleteText();
    }

    @Override
    public void redo() {
        document.appendText(text);
    }
}
